<?php
/**
 * ===============================================
 * 版权所有 2019-2050 青岛铁锤科技有限公司，并保留所有权利。
 * 网站地址: http://www.huaxianling.com
 * ===============================================
 * Author: Happy dong
 * Created Time: 2019-07-11 19:50
 *
 * Version: 2.0
 */

namespace App\Modules\Order\Repositories;


use App\Models\CommentResource;
use App\Modules\Order\Validators\CommentResourceValidator;
use Flower\Core\Repository\Eloquent\BaseRepository;

class CommentResourceRepository extends BaseRepository
{
	public function model()
	{
		return CommentResource::class;
	}

	public function validator()
	{
		return CommentResourceValidator::class;
	}

	/**
	 *  插入评论资源数据
	 * @param $commentId int
	 * @param $memberId int
	 * @param $image  array
	 * @param $video  int
	 * @return mixed
	 */
	public function insertData($commentId, $memberId, $image, $video)
	{
		$resourceInfo = [];
		if(!empty($image)){

		$resourceInfo = array_map(function ($v) {
			return [
				'type' => config('constant.resourceType.picture'), 'resource_id' => $v
			];
		}, $image);
		}
		if(!empty($video)){
			array_push($resourceInfo, ['type' => config('constant.resourceType.video'), 'resource_id' => $video]);
		}

		$resourceList = array_map(function ($v) use ($commentId, $memberId) {
			return [
				'comment_id'  => $commentId,
				'member_id'   => $memberId,
				'type'        => $v['type'],
				'resource_id' => $v['resource_id'],
			];
		}, $resourceInfo);

		return $this->model->insert($resourceList);
	}
}